using IrisGenerator.Common.Modules;
using IrisGenerator.Common.Tools;
namespace IrisGenerator.Common.Core
{


    public partial class Casing
    {

        private System.Nullable<System.Guid> _casId;

        private string _casName;

        private string _casDescription;

        private FormaterConfigurationCollection _formaterConfigurationCollection;

        public virtual System.Nullable<System.Guid> CasId
        {
            get
            {
                return _casId;
            }
            set
            {
                _casId = value;
            }
        }

        public virtual string CasName
        {
            get
            {
                return _casName;
            }
            set
            {
                _casName = value;
            }
        }

        public virtual string CasDescription
        {
            get
            {
                return _casDescription;
            }
            set
            {
                _casDescription = value;
            }
        }

        public virtual FormaterConfigurationCollection FormaterConfigurationCollection
        {
            get
            {
                if ((this._formaterConfigurationCollection == null))
                {
                    _formaterConfigurationCollection = FormaterConfiguration.Select_FORMATER_CONFIGURATION_By_CAS_ID(this.CasId);
                }
                return this._formaterConfigurationCollection;
            }
        }

        private void Clean()
        {
            this.CasId = null;
            this.CasName = string.Empty;
            this.CasDescription = string.Empty;
            this._formaterConfigurationCollection = null;
        }

        private void Fill(System.Data.DataRow dr)
        {
            this.Clean();
            if ((dr["CAS_ID"] != System.DBNull.Value))
            {
                this.CasId = ((System.Nullable<System.Guid>)(dr["CAS_ID"]));
            }
            if ((dr["CAS_NAME"] != System.DBNull.Value))
            {
                this.CasName = ((string)(dr["CAS_NAME"]));
            }
            if ((dr["CAS_DESCRIPTION"] != System.DBNull.Value))
            {
                this.CasDescription = ((string)(dr["CAS_DESCRIPTION"]));
            }
        }

        public static CasingCollection GetAll()
        {
            IrisGenerator.Dal.Casing dbo = null;
            try
            {
                dbo = new IrisGenerator.Dal.Casing();
                System.Data.DataSet ds = dbo.CASING_Select_All();
                CasingCollection collection = new CasingCollection();
                if (GlobalTools.IsSafeDataSet(ds))
                {
                    for (int i = 0; (i < ds.Tables[0].Rows.Count); i = (i + 1))
                    {
                        Casing obj = new Casing();
                        obj.Fill(ds.Tables[0].Rows[i]);
                        if ((obj != null))
                        {
                            collection.Add(obj);
                        }
                    }
                }
                return collection;
            }
            catch (System.Exception)
            {
                throw;
            }
            finally
            {
                if ((dbo != null))
                {
                    dbo.Dispose();
                }
            }
        }

        public static Casing Load(System.Nullable<System.Guid> CAS_ID)
        {
            IrisGenerator.Dal.Casing dbo = null;
            try
            {
                dbo = new IrisGenerator.Dal.Casing();
                System.Data.DataSet ds = dbo.CASING_Select_One(CAS_ID);
                Casing obj = null;
                if (GlobalTools.IsSafeDataSet(ds))
                {
                    if ((ds.Tables[0].Rows.Count > 0))
                    {
                        obj = new Casing();
                        obj.Fill(ds.Tables[0].Rows[0]);
                    }
                }
                return obj;
            }
            catch (System.Exception)
            {
                throw;
            }
            finally
            {
                if ((dbo != null))
                {
                    dbo.Dispose();
                }
            }
        }

        public virtual void Load()
        {
            IrisGenerator.Dal.Casing dbo = null;
            try
            {
                dbo = new IrisGenerator.Dal.Casing();
                System.Data.DataSet ds = dbo.CASING_Select_One(this.CasId);
                if (GlobalTools.IsSafeDataSet(ds))
                {
                    if ((ds.Tables[0].Rows.Count > 0))
                    {
                        this.Fill(ds.Tables[0].Rows[0]);
                    }
                }
            }
            catch (System.Exception)
            {
                throw;
            }
            finally
            {
                if ((dbo != null))
                {
                    dbo.Dispose();
                }
            }
        }

        public virtual void Insert()
        {
            IrisGenerator.Dal.Casing dbo = null;
            try
            {
                dbo = new IrisGenerator.Dal.Casing();
                dbo.CASING_Insert(this.CasName, this.CasDescription);
            }
            catch (System.Exception)
            {
                throw;
            }
            finally
            {
                if ((dbo != null))
                {
                    dbo.Dispose();
                }
            }
        }

        public virtual void Delete()
        {
            IrisGenerator.Dal.Casing dbo = null;
            try
            {
                dbo = new IrisGenerator.Dal.Casing();
                dbo.CASING_Delete(this.CasId);
            }
            catch (System.Exception)
            {
                throw;
            }
            finally
            {
                if ((dbo != null))
                {
                    dbo.Dispose();
                }
            }
        }

        public virtual void Update()
        {
            IrisGenerator.Dal.Casing dbo = null;
            try
            {
                dbo = new IrisGenerator.Dal.Casing();
                dbo.CASING_Update(this.CasId, this.CasName, this.CasDescription);
            }
            catch (System.Exception)
            {
                throw;
            }
            finally
            {
                if ((dbo != null))
                {
                    dbo.Dispose();
                }
            }
        }
    }
}
